<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reference extends CI_Controller {

	public function index() { }

	public function getReferences() {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getReferences();
		$cursor->sort(array('title' => 1));
		echo json_encode(iterator_to_array($cursor));
	}
	public function getReference($id) {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getReference($id);
		echo json_encode($cursor);
	}

	public function getPlaces() {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getPlaces();
		echo json_encode(iterator_to_array($cursor));
	}

	public function getPersons() {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getPersons();
		echo json_encode(iterator_to_array($cursor));
	}

	public function getPlace($id) {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getPlace($id);
		echo json_encode($cursor);
	}

	public function getPerson($id) {
		$this->load->model('Model_reference');
		$cursor = $this->Model_reference->getPerson($id);
		echo json_encode($cursor);
	}

	// ====================================================================================

	public function addReference() {
		$data = $this->input->post('data');
		if(!$data) {
			echo 'error';
			return;
		}
		$this->load->model('Model_reference');
		$rs = $this->Model_reference->addReference($data);

		print_r($data);
	}

	public function updateReference() {
		$data = $this->input->post('data');
		$id = $this->input->post('lsId');
		$this->load->model('Model_reference');
		$rs = $this->Model_reference->update_reference($data, $id);
		print_r($data);
	}

}

?>